home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / clchat413.lha / CLChat413 / ChatBot / source / sendchatbotfile.c < prev   
C/C++ Source or Header  |  1995-10-25  |  2KB  |  96 lines

  1. #define __USE_SYSBASE
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <dos/dostags.h>
  5. #include <bsdsocket.h>
  6. #include <string.h>
  7.  
  8. #include "rev.h"
  9.  
  10. char version[]á= { "$VER: SendChatBotFile " VERTAG };
  11.  
  12. __aligned struct FileInfoBlock fib;
  13.  
  14. //    sprintf() replacement
  15. static UWORD fmtfunc[] = {á0x16c0, 0x4e75 };
  16. void __stdargs sprintf( char *to, char *fmt, ... )
  17. {
  18.     RawDoFmt( fmt, &fmt + 1, (APTR)fmtfunc, to );
  19. }
  20.  
  21. int __stdargs main( char *dummy )
  22. {
  23.     struct RDArgs *rda;
  24.     struct args {
  25.         char *botid;
  26.         char *nick;
  27.         char *file;
  28.         char *dcccmd;
  29.     } args;
  30.  
  31.     args.dcccmd = "DCC.SEND.AS225";
  32.     rda = ReadArgs( "BOTID/A,NICK/A,FILENAME/A,DCCCMD", &args, NULL );
  33.     if( rda )
  34.     {
  35.         struct ipcmsg {
  36.             struct Message m;
  37.             char data[á256 ];
  38.         } im;
  39.         char servername[á128 ];
  40.         char dcccmd[á256 ];
  41.         struct MsgPort *sp;
  42.         BPTR l;
  43.         int port = 1200 + ( time( NULL ) % 2000 );
  44.         
  45.         l = Lock( args.file, SHARED_LOCK );
  46.         if( !l )
  47.         {
  48.             Printf( "SendChatBotFile: file %s not found\n", args.file );
  49.             FreeArgs( rda );
  50.             return( 10 );
  51.         }
  52.         Examine( l, &fib );
  53.         UnLock( l );
  54.  
  55.         sprintf( dcccmd, "RUN %s ORIGINATE NICK %s %s PORT %lu SIZE %lu",
  56.             args.dcccmd,
  57.             args.nick,
  58.             args.file,
  59.             port,
  60.             fib.fib_Size
  61.         );
  62.  
  63.         Printf( "starting \"%s\"\n", dcccmd );
  64.         SystemTags( dcccmd,
  65.             TAG_DONE 
  66.         );
  67.  
  68.         strcpy( servername, "CHATBOT_" );
  69.         strcat( servername, args.botid );
  70.         strupr( servername );
  71.  
  72.         sprintf( im.data, "/QMSG %s \001DCC SEND %s %lu %lu %lu\001",
  73.             args.nick,
  74.             FilePart( args.file ),
  75.             gethostid(),
  76.             port,
  77.             fib.fib_Size
  78.         );
  79.  
  80.         if( sp = FindPort( servername ) )
  81.         {
  82.             im.m.mn_ReplyPort = CreateMsgPort();
  83.             PutMsg( sp, &im );
  84.             WaitPort( im.m.mn_ReplyPort );
  85.             GetMsg( im.m.mn_ReplyPort );
  86.             DeleteMsgPort( im.m.mn_ReplyPort );
  87.         }
  88.         else
  89.             Printf( "SendChatBotFile: No Bot with ID \"%s\" found!\n", args.botid );
  90.         FreeArgs( rda );
  91.     }
  92.     else
  93.         PrintFault( IoErr(), "SendChatBot" );
  94.     return( 0 );
  95. }
  96.